package com.useeinfo.oa.modules.task.entity;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.useeinfo.framework.extend.entity.SuperClassEntity;
import com.useeinfo.framework.sugar.tools.Configuration;
import com.useeinfo.framework.sugar.tools.DateTimeUtils;
import com.useeinfo.framework.sugar.tools.StringConverters;
import com.useeinfo.oa.modules.base.entity.*;
import com.useeinfo.oa.modules.security.entity.SystemUser;
import com.useeinfo.oa.modules.task.enums.TaskAssignTypeEnum;
import com.useeinfo.oa.modules.task.enums.TaskOrderStatusEnum;
import com.useeinfo.oa.modules.task.enums.TaskSourceEnum;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.*;

/**
 * @auther: bin.liu
 * @Date: 2019/6/14 16:48
 * @Description: 任务工单表
 */
@Entity
@Table(name = "task_order")
public class TaskOrder extends SuperClassEntity<TaskOrder> {

    /**
     * 流水号
     */
    private String serial;

    /**
     * 工单名称
     */
    private String orderName;

    /**
     * 工单类型(数据字典中的)
     */
    @ManyToOne
    @JoinColumn(name = "order_type")
    private DictInfo orderType;

    /**
     * 工单状态
     */
    @Enumerated(value = EnumType.STRING)
    @Column(name = "task_order_status")
    private TaskOrderStatusEnum taskOrderStatus;

    /**
     * 任务来源
     */
    @Enumerated(value = EnumType.STRING)
    @Column(name = "source")
    private TaskSourceEnum taskSourceEnum;

    /**
     * 任务发布人
     */
    @ManyToOne
    @JoinColumn(name = "create_user_id")
    private SystemUser createUser;

    /**
     * 任务部门
     */
    @ManyToOne
    @JoinColumn(name = "organization_id")
    private Organization organization;

    /**
     * 任务地址
     */
    private String taskAddress;

    /**
     * 任务内容
     */
    private String taskContent;

    /**
     * 任务照片
     */
    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "task_photo", joinColumns = {
            @JoinColumn(name = "task_order_id", referencedColumnName = "id")},
            inverseJoinColumns = {@JoinColumn(name = "resource_id", referencedColumnName = "id")})
    private Set<Resource> taskPhoto = new HashSet<>();

    /**
     * 任务区域
     */
    @ManyToOne
    @JoinColumn(name = "task_area_id")
    private Area taskArea;

    /**
     * 接单人
     */
    @ManyToOne
    @JoinColumn(name = "receive_user_id")
    private SystemUser receiveUser;

    /**
     * 接单时间
     */
    @Temporal(TemporalType.TIMESTAMP)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date receiveTime;

    /**
     * 撤回人
     */
    @ManyToOne
    @JoinColumn(name = "cancel_user_id")
    private SystemUser cancelUser;

    /**
     * 撤回时间
     */
    @Temporal(TemporalType.TIMESTAMP)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date cancelTime;

    /**
     * 是否指派
     */
    @Column(columnDefinition = "bit default 0")
    private boolean assign;

    /**
     * 指派人
     */
    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "task_assign_users", joinColumns = {
            @JoinColumn(name = "task_order_id", referencedColumnName = "id")},
            inverseJoinColumns = {@JoinColumn(name = "user_id", referencedColumnName = "id")})
    private Set<SystemUser> taskAssignUsers = new HashSet<>();

    /**
     * 指派岗位
     */
    @ManyToMany
    @JoinTable(name = "task_assign_positions", joinColumns = {
            @JoinColumn(name = "task_order_id", referencedColumnName = "id")},
            inverseJoinColumns = {@JoinColumn(name = "position_id", referencedColumnName = "id")})
    private Set<Position> taskAssignPositions = new HashSet<>();

    /**
     * 指派类型
     */
    @Enumerated(value = EnumType.STRING)
    @Column(name = "task_assign_type")
    private TaskAssignTypeEnum taskAssignTypeEnum;

    @ManyToOne
    @JoinColumn(name = "auditFlow_id")
    private AuditFlow auditFlow;

    /**
     * 完成审批流名称
     */
    private String flowName;

    /**
     * 当前完成审批到第几级
     */
    private int auditLevel;

    /**
     * 完成审批流级数
     */
    private int level;

    /**
     * 完成审批流（[{"organizationId":"1","nodeTypeEnum":"USER","relationId":"2"},{}]）
     */
    @Column(columnDefinition = "longtext")
    private String flow;

    /**
     * 当前审批部门
     */
    @ManyToOne
    @JoinColumn(name = "audit_organization_id")
    private Organization auditOrganization;

    /**
     * 当前审批人
     */
    @ManyToOne
    @JoinColumn(name = "auidt_user_id")
    private SystemUser auditUser;

    /**
     * 审批岗位
     */
    @ManyToOne
    @JoinColumn(name = "audit_position_id")
    private Position auditPosition;

    /**
     * 审核通过的人
     */
    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "task_audited_users", joinColumns = {
            @JoinColumn(name = "task_order_id", referencedColumnName = "id")},
            inverseJoinColumns = {@JoinColumn(name = "user_id", referencedColumnName = "id")})
    private Set<SystemUser> hasAuditedUser = new HashSet<SystemUser>();

    /**
     * 关联审批纪录
     */
    @OneToMany(mappedBy = "taskOrder", fetch = FetchType.LAZY)
    private Set<TaskAuditOrder> taskAuditOrders = new HashSet<>();

    /**
     * 所属企业
     */
    @ManyToOne
    @JoinColumn(name = "enterprise_id")
    private Enterprise enterprise;

    /**
     * 总工时
     */
    private long totalWorkingHours;

    /**
     * 我的工时
     */
    private long workingHours;

    /**
     * 完成照片
     */
    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "task_finish_photo", joinColumns = {
            @JoinColumn(name = "task_order_id", referencedColumnName = "id")},
            inverseJoinColumns = {@JoinColumn(name = "resource_id", referencedColumnName = "id")})
    private Set<Resource> taskFinishPhoto = new HashSet<>();

    /**
     * 录音
     */
    @ManyToOne
    @JoinColumn(name = "recording_id")
    private Resource resource;

    /**
     * 要求到场时间
     */
    @Temporal(TemporalType.TIMESTAMP)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date requirePresenceTime;

    /**
     * 到场时间
     */
    @Temporal(TemporalType.TIMESTAMP)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date presenceTime;

    /**
     * 到场后的经度
     */
    @Column(precision = 12, scale = 6)
    private BigDecimal longitude;

    /**
     * 到场后的纬度
     */
    @Column(precision = 12, scale = 6)
    private BigDecimal latitude;

    /**
     * 要求完成时间
     */
    @Temporal(TemporalType.TIMESTAMP)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date requireFinishTime;

    /**
     * 任务完成时间
     */
    @Temporal(TemporalType.TIMESTAMP)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date taskFinishTime;

    /**
     * 是否完成
     */
    @Column(columnDefinition = "bit default 0")
    private boolean finish;

    /**
     * 完成结果描述
     */
    private String finishDescription;

    /**
     * 未完成理由
     */
    private String unFinishReason;

    /**
     * 任务工单参与人
     */
    @OneToMany(mappedBy = "taskOrder")
    private Set<TaskOrderPartner> taskOrderPartners = new HashSet<>();

    /**
     * 终审备注
     */
    private String lastRemark;

    /**
     * 终审评分
     */
    @Column(columnDefinition = "int default 0")
    private int lastScore;

    public String getSerial() {
        return serial;
    }

    public void setSerial(String serial) {
        this.serial = serial;
    }

    public String getOrderName() {
        return orderName;
    }

    public void setOrderName(String orderName) {
        this.orderName = orderName;
    }

    public DictInfo getOrderType() {
        return orderType;
    }

    public void setOrderType(DictInfo orderType) {
        this.orderType = orderType;
    }

    public TaskOrderStatusEnum getTaskOrderStatus() {
        return taskOrderStatus;
    }

    public void setTaskOrderStatus(TaskOrderStatusEnum taskOrderStatus) {
        this.taskOrderStatus = taskOrderStatus;
    }

    public TaskSourceEnum getTaskSourceEnum() {
        return taskSourceEnum;
    }

    public void setTaskSourceEnum(TaskSourceEnum taskSourceEnum) {
        this.taskSourceEnum = taskSourceEnum;
    }

    public SystemUser getCreateUser() {
        return createUser;
    }

    public void setCreateUser(SystemUser createUser) {
        this.createUser = createUser;
    }

    public Organization getOrganization() {
        return organization;
    }

    public void setOrganization(Organization organization) {
        this.organization = organization;
    }

    public String getTaskAddress() {
        return taskAddress;
    }

    public void setTaskAddress(String taskAddress) {
        this.taskAddress = taskAddress;
    }

    public String getTaskContent() {
        return taskContent;
    }

    public void setTaskContent(String taskContent) {
        this.taskContent = taskContent;
    }

    public Set<Resource> getTaskPhoto() {
        return taskPhoto;
    }

    public void setTaskPhoto(Set<Resource> taskPhoto) {
        this.taskPhoto = taskPhoto;
    }

    public Area getTaskArea() {
        return taskArea;
    }

    public void setTaskArea(Area taskArea) {
        this.taskArea = taskArea;
    }

    public SystemUser getReceiveUser() {
        return receiveUser;
    }

    public void setReceiveUser(SystemUser receiveUser) {
        this.receiveUser = receiveUser;
    }

    public Date getReceiveTime() {
        return receiveTime;
    }

    public void setReceiveTime(Date receiveTime) {
        this.receiveTime = receiveTime;
    }

    public SystemUser getCancelUser() {
        return cancelUser;
    }

    public void setCancelUser(SystemUser cancelUser) {
        this.cancelUser = cancelUser;
    }

    public Date getCancelTime() {
        return cancelTime;
    }

    public void setCancelTime(Date cancelTime) {
        this.cancelTime = cancelTime;
    }

    public boolean isAssign() {
        return assign;
    }

    public void setAssign(boolean assign) {
        this.assign = assign;
    }

    public Set<SystemUser> getTaskAssignUsers() {
        return taskAssignUsers;
    }

    public void setTaskAssignUsers(Set<SystemUser> taskAssignUsers) {
        this.taskAssignUsers = taskAssignUsers;
    }

    public Set<Position> getTaskAssignPositions() {
        return taskAssignPositions;
    }

    public void setTaskAssignPositions(Set<Position> taskAssignPositions) {
        this.taskAssignPositions = taskAssignPositions;
    }

    public TaskAssignTypeEnum getTaskAssignTypeEnum() {
        return taskAssignTypeEnum;
    }

    public void setTaskAssignTypeEnum(TaskAssignTypeEnum taskAssignTypeEnum) {
        this.taskAssignTypeEnum = taskAssignTypeEnum;
    }

    public AuditFlow getAuditFlow() {
        return auditFlow;
    }

    public void setAuditFlow(AuditFlow auditFlow) {
        this.auditFlow = auditFlow;
    }

    public String getFlowName() {
        return flowName;
    }

    public void setFlowName(String flowName) {
        this.flowName = flowName;
    }

    public int getAuditLevel() {
        return auditLevel;
    }

    public void setAuditLevel(int auditLevel) {
        this.auditLevel = auditLevel;
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public String getFlow() {
        return flow;
    }

    public void setFlow(String flow) {
        this.flow = flow;
    }

    public Organization getAuditOrganization() {
        return auditOrganization;
    }

    public void setAuditOrganization(Organization auditOrganization) {
        this.auditOrganization = auditOrganization;
    }

    public SystemUser getAuditUser() {
        return auditUser;
    }

    public void setAuditUser(SystemUser auditUser) {
        this.auditUser = auditUser;
    }

    public Position getAuditPosition() {
        return auditPosition;
    }

    public void setAuditPosition(Position auditPosition) {
        this.auditPosition = auditPosition;
    }

    public Set<SystemUser> getHasAuditedUser() {
        return hasAuditedUser;
    }

    public void setHasAuditedUser(Set<SystemUser> hasAuditedUser) {
        this.hasAuditedUser = hasAuditedUser;
    }

    public Set<TaskAuditOrder> getTaskAuditOrders() {
        return taskAuditOrders;
    }

    public void setTaskAuditOrders(Set<TaskAuditOrder> taskAuditOrders) {
        this.taskAuditOrders = taskAuditOrders;
    }

    public Enterprise getEnterprise() {
        return enterprise;
    }

    public void setEnterprise(Enterprise enterprise) {
        this.enterprise = enterprise;
    }

    public long getTotalWorkingHours() {
        return totalWorkingHours;
    }

    public void setTotalWorkingHours(long totalWorkingHours) {
        this.totalWorkingHours = totalWorkingHours;
    }

    public long getWorkingHours() {
        return workingHours;
    }

    public void setWorkingHours(long workingHours) {
        this.workingHours = workingHours;
    }

    public Set<Resource> getTaskFinishPhoto() {
        return taskFinishPhoto;
    }

    public void setTaskFinishPhoto(Set<Resource> taskFinishPhoto) {
        this.taskFinishPhoto = taskFinishPhoto;
    }

    public Resource getResource() {
        return resource;
    }

    public void setResource(Resource resource) {
        this.resource = resource;
    }

    public Date getRequirePresenceTime() {
        return requirePresenceTime;
    }

    public void setRequirePresenceTime(Date requirePresenceTime) {
        this.requirePresenceTime = requirePresenceTime;
    }

    public Date getPresenceTime() {
        return presenceTime;
    }

    public void setPresenceTime(Date presenceTime) {
        this.presenceTime = presenceTime;
    }

    public BigDecimal getLongitude() {
        return longitude;
    }

    public void setLongitude(BigDecimal longitude) {
        this.longitude = longitude;
    }

    public BigDecimal getLatitude() {
        return latitude;
    }

    public void setLatitude(BigDecimal latitude) {
        this.latitude = latitude;
    }

    public Date getRequireFinishTime() {
        return requireFinishTime;
    }

    public void setRequireFinishTime(Date requireFinishTime) {
        this.requireFinishTime = requireFinishTime;
    }

    public Date getTaskFinishTime() {
        return taskFinishTime;
    }

    public void setTaskFinishTime(Date taskFinishTime) {
        this.taskFinishTime = taskFinishTime;
    }

    public boolean isFinish() {
        return finish;
    }

    public void setFinish(boolean finish) {
        this.finish = finish;
    }

    public String getFinishDescription() {
        return finishDescription;
    }

    public void setFinishDescription(String finishDescription) {
        this.finishDescription = finishDescription;
    }

    public String getUnFinishReason() {
        return unFinishReason;
    }

    public void setUnFinishReason(String unFinishReason) {
        this.unFinishReason = unFinishReason;
    }

    public Set<TaskOrderPartner> getTaskOrderPartners() {
        return taskOrderPartners;
    }

    public void setTaskOrderPartners(Set<TaskOrderPartner> taskOrderPartners) {
        this.taskOrderPartners = taskOrderPartners;
    }

    public String getLastRemark() {
        return lastRemark;
    }

    public void setLastRemark(String lastRemark) {
        this.lastRemark = lastRemark;
    }

    public int getLastScore() {
        return lastScore;
    }

    public void setLastScore(int lastScore) {
        this.lastScore = lastScore;
    }

    @Override
    public JSONObject toJSONObject() {
        JSONObject jsonObject = super.toJSONObject();
        jsonObject.put("serial", StringConverters.null2String(getSerial()));
        jsonObject.put("enterpriseName", Optional.ofNullable(getEnterprise()).map(Enterprise::getEnterpriseName).orElse(""));
        jsonObject.put("orderName", StringConverters.null2String(getOrderName()));

        jsonObject.put("orderStatusName", Optional.ofNullable(getTaskOrderStatus()).map(TaskOrderStatusEnum::getName).orElse(""));
        jsonObject.put("orderStatusCode", Optional.ofNullable(getTaskOrderStatus()).map(TaskOrderStatusEnum::getCode).orElse(""));
        jsonObject.put("orderTypeName", getOrderType() == null ? "" : getOrderType().getPropertyName());
        jsonObject.put("taskSourceName", Optional.ofNullable(getTaskSourceEnum()).map(TaskSourceEnum::getName).orElse(""));
        jsonObject.put("taskSourceCode", Optional.ofNullable(getTaskSourceEnum()).map(TaskSourceEnum::getCode).orElse(""));
        jsonObject.put("createUser", getCreateUser() == null ? "" : getCreateUser().getUserName());
        jsonObject.put("createUserMobile", getCreateUser() == null ? "" : getCreateUser().getMobile());
        jsonObject.put("taskAddress", StringConverters.null2String(getTaskAddress()));
        jsonObject.put("taskContent", StringConverters.null2String(getTaskContent()));
        jsonObject.put("taskArea", getTaskArea() == null ? "" : getTaskArea().getAreaName());
        jsonObject.put("receiveUser", getReceiveUser() == null ? "" : getReceiveUser().getUserName());
        if (getReceiveTime() != null) {
            jsonObject.put("receiveTime", DateTimeUtils.format(getReceiveTime(), "yyyy-MM-dd HH:mm:ss"));
        } else {
            jsonObject.put("receiveTime", "");
        }
        jsonObject.put("cancelUser", getCancelUser() == null ? "" : getCancelUser().getUserName());
        if (getCancelTime() != null) {
            jsonObject.put("cancelTime", DateTimeUtils.format(getCancelTime(), "yyyy-MM-dd HH:mm:ss"));
        } else {
            jsonObject.put("cancelTime", "");
        }
        jsonObject.put("assign",StringConverters.null2Boolean(isAssign()) ? "是" : "否");
        jsonObject.put("taskAssignType", getTaskAssignTypeEnum() != null && isAssign() ? ("USER".equals(getTaskAssignTypeEnum().getCode()) ? "指派人员" : "指派岗位") : "未指派");
        List<SystemUser> assignUsers = new ArrayList<>(getTaskAssignUsers());
        assignUsers.sort((o1, o2) -> o1.getId() < o2.getId() ? -1 : 1);
        JSONArray assignUsersArray = new JSONArray();
        for (SystemUser systemUser : assignUsers) {
            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("userName", StringConverters.null2String(systemUser.getUserName()));
            jsonObject1.put("userId", systemUser.getId());
            assignUsersArray.add(jsonObject1);
        }

        List<Position> assignPositions = new ArrayList<>(getTaskAssignPositions());
        assignPositions.sort((o1, o2) -> o1.getId() < o2.getId() ? -1 : 1);
        JSONArray assignPositionsArray = new JSONArray();
        for (Position position : assignPositions) {
            JSONObject jsonObject2 = new JSONObject();
            jsonObject2.put("positionName", StringConverters.null2String(position.getName()));
            jsonObject2.put("positionId", position.getId());
            assignPositionsArray.add(jsonObject2);
        }

        jsonObject.put("assignUsersArray",assignUsersArray);
        jsonObject.put("assignPositionsArray",assignPositionsArray);

        jsonObject.put("workingHours", StringConverters.null2String(getWorkingHours()));
        jsonObject.put("totalWorkingHours", StringConverters.null2String(getTotalWorkingHours()));

        // 任务照片
        List<Resource> taskPhotos = new ArrayList<>(getTaskPhoto());
        taskPhotos.sort((o1, o2) -> o1.getId() < o2.getId() ? -1 : 1);
        JSONArray taskPhotosArray = new JSONArray();
        if (CollectionUtils.isNotEmpty(taskPhotos)) {
            for (Resource resource : taskPhotos) {
                taskPhotosArray.add(resource.getPath());
            }
        }
        jsonObject.put("taskPhotos", taskPhotosArray);
        jsonObject.put("taskPhoto1", taskPhotosArray != null && taskPhotosArray.size() > 0 ? Configuration.getConfigurationByName("hostUrl") + taskPhotosArray.get(0).toString() : "");

        // 任务完成照片
        List<Resource> taskFinishPhotos = new ArrayList<>(getTaskFinishPhoto());
        taskFinishPhotos.sort((o1, o2) -> o1.getId() < o2.getId() ? -1 : 1);
        JSONArray taskFinishPhotosArray = new JSONArray();
        JSONArray finishPhotoIdArray = new JSONArray();
        if (CollectionUtils.isNotEmpty(taskFinishPhotos)) {
            for (Resource resource : taskFinishPhotos) {
                taskFinishPhotosArray.add(resource.getPath());
                finishPhotoIdArray.add(resource.getId());
            }
        }
        jsonObject.put("finishPhotoIds",finishPhotoIdArray!=null? finishPhotoIdArray:"");
        jsonObject.put("taskFinishPhotos", taskFinishPhotosArray);
        jsonObject.put("taskFinishPhoto1", taskFinishPhotosArray != null && taskFinishPhotosArray.size() > 0 ? Configuration.getConfigurationByName("hostUrl") + taskFinishPhotosArray.get(0).toString() : "");

        jsonObject.put("word", getResource() != null ? Configuration.getConfigurationByName("hostUrl") + getResource().getPath() : "");
        jsonObject.put("level", getLevel());
        jsonObject.put("auditLevel", getAuditLevel());
        jsonObject.put("auditUser", getAuditUser() == null ? "" : getAuditUser().getUserName());

        if (getRequirePresenceTime() != null){
            jsonObject.put("requirePresenceTime", DateTimeUtils.format(getRequirePresenceTime(), "yyyy-MM-dd HH:mm:ss"));
        } else {
            jsonObject.put("requirePresenceTime", "");
        }

        if (getPresenceTime() != null){
            jsonObject.put("presenceTime", DateTimeUtils.format(getPresenceTime(), "yyyy-MM-dd HH:mm:ss"));
        } else {
            jsonObject.put("presenceTime", "");
        }

        if (getRequireFinishTime() != null){
            jsonObject.put("requireFinishTime", DateTimeUtils.format(getRequireFinishTime(), "yyyy-MM-dd HH:mm:ss"));
        } else {
            jsonObject.put("requireFinishTime", "");
        }
        if (getTaskFinishTime() != null){
            jsonObject.put("taskFinishTime", DateTimeUtils.format(getTaskFinishTime(), "yyyy-MM-dd HH:mm:ss"));
        } else {
            jsonObject.put("taskFinishTime", "");
        }
        jsonObject.put("longitude", getLongitude());
        jsonObject.put("latitude", getLatitude());
        jsonObject.put("finish", isFinish() ? "已完成":"未完成");
        // 参与人
        List<TaskOrderPartner> taskOrderPartners = new ArrayList<>(getTaskOrderPartners());
        taskOrderPartners.sort((o1, o2) -> o1.getId() < o2.getId() ? -1 : 1);
        JSONArray taskOrderPartnersArray = new JSONArray();
        if (CollectionUtils.isNotEmpty(taskOrderPartners)) {
            for (TaskOrderPartner partner : taskOrderPartners) {
                taskOrderPartnersArray.add(partner.toJSONObject());
            }
        }
        jsonObject.put("organizationName",getOrganization() == null ? "" : getOrganization().getOrganizationName());
        jsonObject.put("taskOrderPartnersArray", taskOrderPartnersArray);
        jsonObject.put("finishDescription", Optional.ofNullable(getFinishDescription()).orElse(""));
        jsonObject.put("unFinishReason", Optional.ofNullable(getUnFinishReason()).orElse(""));
        jsonObject.put("lastRemark",Optional.ofNullable(getLastRemark()).orElse(""));
        jsonObject.put("lastScore",getLastScore());
        // 审批记录
        List<TaskAuditOrder>  taskAuditOrders = new ArrayList<>(getTaskAuditOrders());
        taskAuditOrders.sort((o1, o2) -> o1.getId() < o2.getId() ? -1 : 1);
        JSONArray taskAuditOrdersArray = new JSONArray();
        if (CollectionUtils.isNotEmpty(taskAuditOrders)) {
            for (TaskAuditOrder auditOrder : taskAuditOrders) {
                taskAuditOrdersArray.add(auditOrder.toJSONObject());
            }
        }
        jsonObject.put("taskAuditOrdersArray", taskAuditOrdersArray);

        // 返回实体添加返回审批层数
        String flow = StringConverters.null2String(getFlow());
        int flowLength = 0;
        if (flow != null && !flow.equals("")) {
            flow=flow.replace("[{","").replace("}]","");
            flowLength = flow.split("}").length;
        }

        jsonObject.put("flowSize", flowLength);


        return jsonObject;
    }
}
